Importing the Libraries
import pandas as pd
import yfinance as yf
import datetime
from datetime import date, timedelta
import plotly.graph_objects as go
import plotly.express as px
today = date.today()
d1 = today.strftime("%Y-%m-%d")
end_date= d1
d2 = date.today() - timedelta(days=365)
d2 = d2.strftime("%Y-%m-%d")
start_date = d2
data = yf.download ('GOOG', start=start_date, end=end_date, progress=False)
data["Date"] = data.index
data = data[["Date", "Open", "High", "Low", "Close", "Adj Close", "Volume"]]
data.reset_index(drop=True, inplace=True)
print(data.head())
Date Open High Low Close Adj Close \
0 2022-06-27 118.934998 119.250000 116.000748 116.622498 116.622498
1 2022-06-28 116.350998 117.856499 112.444000 112.571503 112.571503
2 2022-06-29 112.148499 113.664497 111.554001 112.256500 112.256500
3 2022-06-30 110.499496 111.329803 107.309998 109.372498 109.372498
4 2022-07-01 108.336998 109.806351 107.105003 109.081001 109.081001
Volume
0 32840000
1 28232000
2 18628000
3 38046000
4 31028000
figure = go.Figure(data=[go.Candlestick(x=data["Date"], open = data["Open"],
high=data["High"], low=data["Low"],
close=data["Close"])])
figure.update_layout(title ="Google Stock Price Analysis", xaxis_rangeslider_visible=False)
figure.show()
figure = px.bar (data , x="Date",y="Close")
figure.show()
figure = px.line(data, x='Date', y='Close', title='Stock Market Analysis with Rangeslider')
figure.update_xaxes (rangeslider_visible=True)
figure.show()
figure = px. line(data, x='Date', y='Close',title='Stock Market Analysis with Time Period Selectors')
figure.update_xaxes( rangeselector=dict(buttons=list([dict(count=1, label="1m",
step="month", stepmode="backward"), dict(count=6,
label="6m", step="month", stepmode="backward"),
dict(count=3, label="3m", step="month", stepmode="backward"),
dict(count=1, label="1y", step="year", stepmode="backward"), dict(step="all")])))
figure.show()
figure = px.scatter (data, x='Date', y='Close', range_x=['2022-06-20', '2023-06-19'],
title= "Stock Market Analysis by Hiding Weekend Gaps")
figure.update_xaxes( rangebreaks=[ dict(bounds=["sat", "sun"])])
figure.show()